<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $myAggregations array */
	$myAggregations =& $this->requestAttributes['myAggregations'];
	/* @var $editorInAggregations array */
	$editorInAggregations =& $this->requestAttributes['editorInAggregations'];
	
	$user = $repositoryUi->getUser();
	$systemRoles = $user->getSystemRoles(true);

	$gadgetModeUrlParameter = '';
	if($repositoryUi->isGadgetMode())
	{
		$gadgetModeUrlParameter = '?gadget=1';
	}
	$gadgetModeTargetBlank = '';
	if($repositoryUi->isGadgetMode())
	{
		$gadgetModeTargetBlank = 'target="_blank"';
	}
	
	$templateVariables = array();
	$templateVariables['title'] = 'My ESCAPE';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">

<div class="escape_Selection">

<div class="escape_SectionTitle">My <?php print htmlspecialchars($repositoryUi->repository->config['label_aggregations']); ?></div>

<?php
	if($user->hasSystemRole(escape_repository_User::$role_administrator) || $user->hasSystemRole(escape_repository_User::$role_creator) || count($myAggregations) > 0 || count($editorInAggregations) > 0)
	{
?>
<div class="escape_Hint">
<a <?php print $gadgetModeTargetBlank; ?> href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('editorManual'))?>">Manual for editors</a>
</div>
<?php
	}
?>
<?php
	if($user->hasSystemRole(escape_repository_User::$role_administrator) || $user->hasSystemRole(escape_repository_User::$role_creator))
	{
?>
<div class="escape_Section">
<a href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('createAggregation') . $gadgetModeUrlParameter); ?>"><img src="/rsc/img/add.gif" alt="Add" /> Create a new <?php print htmlspecialchars($repositoryUi->repository->config['label_aggregation']); ?></a>
</div>
<?php
	}
?>

<?php
	if(count($myAggregations) > 0)
	{
		usort($myAggregations, array('escape_repository_DataObject', '_compareTitle'));
?>
<div class="escape_Section">
<div>Owner of: <?php $repositoryUi->displayInfoTooltip('These are the ' . $repositoryUi->repository->config['label_aggregations'] . ' where the ' . $repositoryUi->repository->config['label_aggregation'] . ' role "owner" is assigned to you.'); ?></div>

<ul>
<?php
		foreach($myAggregations as $aggregation)
		{
			/* @var $aggregation escape_repository_OreAggregation */
			$title = $aggregation->getTitle();
			if($title === null || $title === "")
			{
				$title = 'Unnamed aggregation ' . $aggregation->getId();
			}
?>
<li><a href="/show/<?php print htmlspecialchars($aggregation->getId() . $gadgetModeUrlParameter); ?>"><?php print htmlspecialchars($title); ?></a></li>
<?php
		}
?>
</ul>

</div>
<?php
	}
?>


<?php
	if(count($editorInAggregations) > 0)
	{
		usort($editorInAggregations, array('escape_repository_DataObject', '_compareTitle'));
?>
<div class="escape_Section">
<div>Editor in: <?php $repositoryUi->displayInfoTooltip('These are the ' . $repositoryUi->repository->config['label_aggregations'] . ' where the ' . $repositoryUi->repository->config['label_aggregation'] . ' role "editor" is assigned to you.'); ?></div>

<ul>
<?php
		foreach($editorInAggregations as $aggregation)
		{
			/* @var $aggregation escape_repository_OreAggregation */
			$title = $aggregation->getTitle();
			if($title === null || $title === "")
			{
				$title = 'Unnamed aggregation ' . $aggregation->getId();
			}
?>
<li><a href="/show/<?php print htmlspecialchars($aggregation->getId() . $gadgetModeUrlParameter); ?>"><?php print htmlspecialchars($title); ?></a></li>
<?php
		}
?>
</ul>

</div>
<?php
	}
?>



</div>

</div>

<?php
	if($repositoryUi->repository->config['myescape_show_my_account_section'])
	{
?>
<div class="escape_Section">
<div class="escape_SectionTitle">My account</div>

<ul>
<?php
		if(count($systemRoles) > 0)
		{
?>
	<li>System roles: <?php print htmlspecialchars(implode(', ', $systemRoles)); ?></li>
<?php
		}
?>
	<li>
		<a href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('account') . $gadgetModeUrlParameter); ?>">Change your account details</a>
	</li>
</ul>

</div>
<?php
	}
?>

<?php
	if($user->hasSystemRole(escape_repository_User::$role_administrator))
	{
?>
<div class="escape_Section">
<div class="escape_SectionTitle">Admin tools</div>

<ul>
	<li>
		<a <?php print $gadgetModeTargetBlank; ?> href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('adminListAggregations')); ?>">Manage <?php print htmlspecialchars($repositoryUi->repository->config['label_aggregations']); ?></a>
	</li>
	<li>
		<a <?php print $gadgetModeTargetBlank; ?> href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('adminListUsers')); ?>">Manage users</a>
	</li>
</ul>

</div>
<?php
	}
?>




<?php $this->displayFooter(); ?>
